var CurrentPlay;

function DelayResizeFancybox(){
		$.fancybox.reposition();
		$.fancybox.update();
}

var AddonMediaPlayer = function(){

	$('a.player').fancybox({
		//maxWidth	: 800,
		//maxHeight	: 600,
		minWidth	: 686,
		autoCenter : true,
		width		: '100%',
		height		: '100%',
		autoSize	: true,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none',
		beforeClose : function(){
			CurrentPlay.pause();
		}
	});

	$('video')
	.mediaelementplayer({
		success: function (mediaElement, domObject) {
			CurrentPlay = mediaElement;
			//DelayResizeFancybox();

			//CurrentPlay.play(); // this auto start


				mediaElement.addEventListener('play', function(e) {
					DelayResizeFancybox();
				}, false);




		}
	});
};


var ConfirmChangeWriter = function(topic)
{
	if ( ! confirm('ท่านต้องการเป็นผู้เขียน \n\n"'+ topic +'"\n\n ใช่หรือไม่') ) return false;
	else return true;
}


/*
jQuery.fn.AddonMediaPlayer = function(){


   return this.each(function(){

	var box = $(this);
	var url = box.attr('url');
	var w = box.attr('width') || 530;
	var h = box.attr('height') || 530 ;
	var embedPlayer = '<video id="player1" src="' +url+ '" tabindex="0"></video>';

	var AddPlayer = '<div align="center"><img src="/template/images/items/irh_player.gif" class="hand player">';
	AddPlayer += '<div id="itplay" style="display:none"><div align="center">'+embedPlayer+'</div>';
	AddPlayer += '</div>';



	box.html(AddPlayer);
	box.click(function(){

			$('img',this).fancybox({
				href : '#itplay',
				//maxWidth	: 800,
				//maxHeight	: 600,
				minWidth	: 666,
				autoCenter : true,
				itToView	: false,
				width		: '110%',
				height		: '110%',
				autoSize	: true,
				closeClick	: false,
				openEffect	: 'none',
				closeEffect	: 'none',
				beforeClose : function(){
					CurrentPlay.pause();
				}
			});

	});


	$('video',box)
	.mediaelementplayer({
		success: function (mediaElement, domObject) {
			CurrentPlay = mediaElement;
			DelayResizeFancybox();

			mediaElement.addEventListener('play', function(e) {
				DelayResizeFancybox();
			}, false);

		}
	})
	.click(function(){ DelayResizeFancybox(); });



   });



};
*/



/*
$.fancybox.reposition()

		$('.itplay').fancybox({
			maxWidth	: 800,
			maxHeight	: 600,
			fitToView	: false,
			width		: '70%',
			height		: '70%',
			autoSize	: false,
			closeClick	: false,
			openEffect	: 'none',
			closeEffect	: 'none'
		});


MediaElement('player1', {success: function(me) {

	me.play();

	me.addEventListener('timeupdate', function() {
		document.getElementById('time').innerHTML = me.currentTime;
	}, false);

	document.getElementById('pp')['onclick'] = function() {
		if (me.paused)
			me.play();
		else
			me.pause();
	};

}});*/